function ajax(options){
    let {type="get",url,data={},success} = options;

    let str ="";
    for(let i in data){
        str += `${i}=${data[i]}&`
    }

    if(type ==="get") url = url + "?" + str.slice(0,str.length-1);

    const xhr = new XMLHttpRequest();
    xhr.open(type,url,true);

    if(type === "get"){
        xhr.send();
    }else{
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhr.send(str.slice(0,str.length-1));
    }

    xhr.onload=function(){
        if(xhr.status === 200){
            success(xhr.responseText);
        }
    }
}